package com.vancouver.knows.ui.fragment.citynews;

import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pangu.ui.browser.LoadableList;
import com.vancouver.knows.R;
import com.vancouver.knows.business.Constants;
import com.vancouver.knows.ui.base.BaseFragment;

/**
 * 城事子内容
 * 
 * @author chenxunlin01
 * 
 */
public class CityNewsChildrenFragment extends BaseFragment {

	public static final int CITYNEWS_TYPE_HOT = 0;
	public static final int CITYNEWS_TYPE_MUSIC_MATCH = 1;
	public static final int CITYNEWS_TYPE_NEWEST = 2;
	public static final int CITYNEWS_TYPE_INFORMATION = 3;
	public static final int CITYNEWS_TYPE_IRRIGATION = 4;
//	public static final int CITYNEWS_TYPE_SEEKHELP = 4;//
	public static final int CITYNEWS_TYPE_SECONDHAND = 5/*5*/;
//	public static final int CITYNEWS_TYPE_LIVE = 6;//
	public static final int CITYNEWS_TYPE_SHIPING = 6/*7*/;


	private String[] titles = null;


	private CityNewsPullControllerView cityNewsPullControllerView;

//	@Override
//	protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//		return null;
//	}
//
//	@Override
//	protected void bindView(View rootView) {
//
//	}

	public static CityNewsChildrenFragment newInstance(int type) {
		CityNewsChildrenFragment fragment = new CityNewsChildrenFragment();
		Bundle bundle = new Bundle();
		bundle.putInt("type", type);
		fragment.setArguments(bundle);

		return fragment;
	}

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		int type = getArguments().getInt("type", CITYNEWS_TYPE_HOT);
		cityNewsPullControllerView = new CityNewsPullControllerView(getActivity());
		if (titles == null || titles.length == 0) {
			titles = getResources().getStringArray(R.array.citynews_tab_titles);
		}
		cityNewsPullControllerView.loadData(type, titles);
		if (getParentFragment() instanceof LoadableList.LoadableListScrollListener) {
			cityNewsPullControllerView.setScrollListener((LoadableList.LoadableListScrollListener) getParentFragment());
		}
		return cityNewsPullControllerView;
	}

	@Override
	public void subHandleMessage(Message msg) {
		switch (msg.what) {
		case Constants.BUSINESS_STATUS_USER_UPVOTE:
		case Constants.BUSINESS_STATUS_USER_DELETE_UPVOTE:
		case Constants.BUSINESS_STATUS_USER_DEL_ARTICLE:
		case Constants.BUSINESS_STATUS_CITYNEWS_COMMENT_COUNT_CHANGE:
			cityNewsPullControllerView.flush();
			break;
		}
	}

	@Override
	protected void bindView(View rootView) {
	}

	public void scrollUp() {
		cityNewsPullControllerView.scrollUp();
	}

}
